Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20 new working GeneralStateTests #148

Merged
merged 1 commit into from
Sep 18, 2018
Merged

20 new working GeneralStateTests #148

merged 1 commit into from
Sep 18, 2018

Conversation

tersec
Copy link
Contributor

@tersec tersec commented Sep 18, 2018

In no particular order:

  • further bounds-checked the SHA3 opcode, which avoids a gas calculation overflow.
  • rewrote writePaddedResult to always write padding for non-extended sections of memory up to the total number of bytes requested written, regardless of input data size. The correct semantics are not to leave them alone, as the previous writePaddedResult did. I find this version a bit simpler, too -- no branches, for example.
  • switched the LOG1, LOG2, LOG3, and LOG4 opcodes to use cleanMemRef, to solve the usual issues that solves. This required moving cleanMemRef to nimbus/vm/interpreter/utils/utils_numeric.nim, where it belongs regardless.
  • removed another couple pointless (because UInt256) validateGte commented lines from the auto-conversion.
  • moved db.increaseBalance(currentCoinbase, gas_cost) to the end of each codepath (yet to be re-merged; e.g., the two error paths are intentionally identical, and most of them will collapse entirely once transactional database usage comes in), separate from its pair db.setBalance(sender, db.getBalance(sender) - gas_cost). This has created a bit more duplication temporarily, but solved around a dozen GeneralStateTests.
  • to begin addressing the suicide coinbase cases, I ensure that coinbases don't spuriously get credited if they're going to be destroyed regardless in the main codepath.

Progress:

  • 758 working tests
  • 1011 skipped tests
  • 565 failing tests, of which 54 don't CALL, or CREATE, and of which 3 (tests/fixtures/GeneralStateTests/stSystemOperationsTest/suicideCoinbase.json, tests/fixtures/GeneralStateTests/stTransactionTest/TransactionFromCoinbaseHittingBlockGasLimit1.json, and tests/fixtures/GeneralStateTests/stTransactionTest/SuicidesMixingCoinbase.json) have neither those nor an empty transaction.to field.

@tersec
Copy link
Contributor Author

tersec commented Sep 18, 2018

The Travis CI build is failing on both Linux and macOS because:

Hint:transaction [Processing]
Hint:eth_keys [Processing]
Hint:secp256k1 [Processing]
Error: unhandled exception: cannot open: /home/travis/.nimble/pkgs/secp256k1-0.1.0/secp256k1_wrapper/secp256k1/src/secp256k1.c [IOError]
       Tip:157 messages have been suppressed, use --verbose to show them.
     Error:Execution failed with exit code 1

It was mentioned in #nimbus-riot last week as well. My local build environment setup script has a workaround, because otherwise I experience it reliably:

git clone --recurse https://github.com/status-im/nim-secp256k1.git
...
cp -npvr ~/nim-secp256k1/secp256k1_wrapper/ ~/.nimble/pkgs/secp256k1-0.1.0/

@coffeepots
Copy link
Contributor

LGTM. writePaddedResult definitely looks better now.
Interested to see how this runs with #139 merged, we got a few extra tests passing with that already, but not sure if they're extras compared to this PR.

@tersec tersec merged commit 048921b into master Sep 18, 2018
@tersec tersec deleted the GST branch September 18, 2018 14:00
@tersec
Copy link
Contributor Author

tersec commented Sep 18, 2018

At least 3 or 4 of them (callcall_, et cetera) are distinct.


# Don't duplicate zero-padding of mem.extend
let paddingOffset = memPos + sourceBytes.len
mem.write(paddingOffset, repeat(paddingValue, max(prevLen - paddingOffset, 0)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid the call to repeat here? It performs a memory allocations that's not really necessary.

The previous code is more convoluted for sure, but it actually seems more economical to me when it comes to branching. There is a potential hidden branch in every call to min and max and you would still call mem.write even when repeat returns a zero-len sequence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think min/max are optimised to not need branches in most compilers, being replaced with cmp and conditional mov, and it does make for easier to read code. However I think there's a lot to be said for explicit code when performance matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zah yes, I'll look into a better approach than repeat. I share your concern here. In this version I went for readability, but to be fair, this code's seems plausibly more performance-sensitive than most in Nimbus. It's worth optimizing.

@coffeepots yes, that min and max are often branchless was part of my thought process. The issue I had with the explicit code was that it created multiple subcases that I found harder to verify were all correct, created some duplication, and obscured the degree to which the different nominally disjoint code flows were similar in practice. I'm not strongly opinionated about this though.

jangko added a commit that referenced this pull request Feb 27, 2024
Make decimal string parser raise ValueError instead of RangeDefect. (#148)
Upgrade github actions to v4 (#149)
jangko added a commit that referenced this pull request Feb 29, 2024
Make decimal string parser raise ValueError instead of RangeDefect. (#148)
Upgrade github actions to v4 (#149)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants